package server

import (
	"github.com/gin-gonic/gin"
	uuid "github.com/satori/go.uuid"
	"github.com/xhyonline/websocket/mod"
	"gopkg.in/olahol/melody.v1"
)

// HandleConnect 处理连接
func (s *server) HandleConnect(session *melody.Session) {
	// 用户数增加 1
	s.UserCountAdd()
	// hash 生成用户全局用户的 ID
	id := uuid.NewV4().String()
	s.Users.Store(id, &mod.User{
		UID:     id,
		Session: session,
	})
	session.Set("uid", id)
	// 给前端返回用户的ID
	s.SocketOutputMarshal(session, gin.H{
		"code": 99,
		"uid":  id,
	})
}
